package com.mission.shaco.warehouse.models.list;

import android.os.Build;

import com.mission.shaco.warehouse.models.Tool;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * Created by Administrator on 2017/6/20.
 */

public class BaseJavaList implements Serializable{

    public transient JSONArray jsonArray = new JSONArray();
    static final int FIRST_INDEX = 0;
    static final  String FILE_NAME = "listview_single";
    public int hello = 0;


    public  JSONArray getList(){

        return jsonArray;
    }

    public void removeFirst(){
        if ( Build.VERSION.SDK_INT<19){
            jsonArray = (new Tool()).JSONRemove(0,jsonArray);
        }else {
            jsonArray.remove(FIRST_INDEX);
        }
    }

    public void reloadData(String itemStr) throws JSONException {
        jsonArray = new JSONArray(itemStr);
    }

    private void writeObject(ObjectOutputStream oos) throws IOException {
        oos.defaultWriteObject();
        oos.writeObject(jsonArray.toString());
    }

    private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException, JSONException {
        ois.defaultReadObject();
        jsonArray = new JSONArray((String) ois.readObject());
    }

    public JSONArray getJsonArray() {
        return jsonArray;
    }

    public void setJsonArray(JSONArray jsonArray) {
        this.jsonArray = jsonArray;
    }
}
